#!/bin/bash

buildflag=
if [[ $# -gt 0 ]] && [[ $1 == debug ]];then
	echo '将打开CSB_DEBUG宏开关进行编译，显示libCSB的内部调试信息'
	buildflag=-DCSB_DEBUG
fi

echo '正在生成动态库到当前目录'
g++ src/*.cpp -o libCSB.so $buildflag -fPIC -shared -O2 -ffast-math -lm -I include
if [[ -f libCSB.so ]]; then
	strip libCSB.so
	echo '成功生成动态库libCSB.so到当前目录'
else
	echo '生成动态库失败'
	exit 0
fi

echo '现在生成静态库'
cachedir=/tmp/$$cache
predir=$(pwd)
mkdir $cachedir
cd $cachedir
g++ $buildflag -c -O2 -ffast-math -I $predir/include $predir/src/*.cpp
ar rcs libCSB.a *.o
if [[ -f libCSB.a ]]; then
	mv libCSB.a $predir
	echo '成功生成静态库libCSB.a到当前目录'
else
	echo '生成静态库失败'
	exit 0
fi
rm -rf $cachedir
